package com.tongda.menu.activity;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.tongda.core.common.Constants;
import com.tongda.core.common.KernalApplication;
import com.tongda.core.repository.MenuCartDao;
import com.tongda.core.repository.MenuDishDao;
import com.tongda.core.service.DishService;
import com.tongda.core.utils.ActivityUtil;
import com.tongda.core.utils.DishUtil;
import com.tongda.core.vo.Dish;
import com.tongda.core.vo.DishesSetDishes;
import com.tongda.core.vo.DishesSetDishesReplace;
import com.tongda.core.vo.SpecialDishe;
import com.tongda.menu.R;
import com.tongda.menu.R.drawable;
import com.tongda.menu.activity.CartActivity.initTuicaiTask;
import com.tongda.menu.util.ActivityMenuUtil;
import com.tongda.menu.widget.BadgeView;
import com.tongda.menu.widget.CircleImageView;
import com.tongda.menu.widget.CustomViewPager;
import com.tongda.menu.widget.FlowLinearLayout;
import com.tongda.menu.widget.ZoomOutPageTransformer;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.Html;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.view.animation.Animation.AnimationListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class ShowActivity extends FragmentActivity{
		
	private Intent intent;
	private String categoryId;
	private int currentposition;
	private List<Dish> datas;
	public static CustomViewPager mViewPager;
	private MenuAdapter mMenuAdapter;
	private DishUtil dish_util;
	private String dishName;
	private MenuDishDao dish_dao;
	private MenuCartDao order_dish_dao;
	Map<String, String> params4Category = new WeakHashMap<String, String>();
	private ImageView movelImg;
	private ImageView moverImg;
	private String page;
	private  int dinerDishesCount;
	private static BadgeView orderNumTv;
	private static KernalApplication application;
	private static ImageLoader imageLoader;
	private static int cartOrderNum;
	public static DisplayImageOptions options;
	private boolean isBlockScreen;
	
	Handler handler = new Handler(){

		@Override
		public void handleMessage(Message msg) {
			super.handleMessage(msg);
			switch(msg.what){
			case Constants.DESCRIBE:
				describeView();
				break;
				default:
					break;
			}
		}
		
	};
	private Dialog dialog;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_show);
		application = KernalApplication.getInstance();
		imageLoader = ActivityMenuUtil.getImageLoader(this);
		options = ActivityMenuUtil.getImageOptions();
		intent = getIntent();
		
		categoryId = intent.getStringExtra("categoryId");
		dishName = intent.getStringExtra("dishName");
		dinerDishesCount = intent.getIntExtra("dinerDishesCount", 0);
		
		dish_dao = MenuDishDao.getInstance(this);
		order_dish_dao = MenuCartDao.getInstance(this);
		dish_util = DishUtil.getInstance(this);
		
		initView();
	}
	
	public void initView(){
		dialog = new Dialog(ShowActivity.this, R.style.TransparentWindowStyle);
		View view = View.inflate(ShowActivity.this, R.layout.wait_layout, null);
		dialog.show();
		dialog.setCanceledOnTouchOutside(false);
		dialog.setContentView(view);
		setBlockScreen(true);
		
		Thread loadDataThread = new Thread(new Runnable() {
			
			@Override
			public void run() {
				if(categoryId!=null){
					currentposition = intent.getIntExtra("position", 0);
					datas = dish_util.getTheDish(categoryId);
				}else if(dishName!=null){
					categoryId = dish_dao.getdcId(dishName);
					params4Category.put("categoryId", categoryId);
					datas = dish_dao.getDishesByParams(params4Category);
					for(int i=0;i<datas.size();i++){
						if(dishName.equals(datas.get(i).getDishesName())){
							currentposition = i;
							break;
						}
					}
				}
				handler.sendEmptyMessage(Constants.DESCRIBE);
			}
		});
		loadDataThread.start();
	}
	
	public void describeView(){
		mViewPager =(CustomViewPager)findViewById(R.id.activity_show_viewpager);
		mMenuAdapter = new MenuAdapter(getSupportFragmentManager(),datas,this);
		
		mViewPager.setAdapter(mMenuAdapter);
		mViewPager.setCurrentItem(currentposition);
		
		movelImg = (ImageView)findViewById(R.id.show_moveL);
		moverImg = (ImageView)findViewById(R.id.show_moveR);
		
		movelImg.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				moverImg.setVisibility(View.VISIBLE);
				if(currentposition>0){
					mViewPager.setCurrentItem(--currentposition);
					movelImg.setVisibility(View.VISIBLE);
				}else{
					movelImg.setVisibility(View.INVISIBLE);
				}
			}
		});
		
		moverImg.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				movelImg.setVisibility(View.VISIBLE);
				if(currentposition<datas.size()-1){
					mViewPager.setCurrentItem(++currentposition);
					moverImg.setVisibility(View.VISIBLE);
				}else{
					moverImg.setVisibility(View.INVISIBLE);
				}
			}
		});
		
	    ImageView show_cart = (ImageView)findViewById(R.id.show_cart);
	    show_cart.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				ActivityUtil.switchActivity(ShowActivity.this, false, CartActivity.class);
				overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
			}
		});
	    
	        orderNumTv =  (BadgeView)findViewById(R.id.show_orderedNumTv);
		    cartOrderNum = dinerDishesCount+ order_dish_dao.getEffectiveCount();
		    orderNumTv.setText(cartOrderNum+"");
		    
		    dialog.dismiss();
		    setBlockScreen(false);
	}
	@Override
	protected void onPause() {
		super.onPause();
		if(dialog!=null && dialog.isShowing()){
			dialog.dismiss();
		}
	}
	
	class MenuAdapter extends FragmentPagerAdapter{
		List<Dish> datas;
		Context context;
		public MenuAdapter(FragmentManager fm,List<Dish> datas,Context context) {
			super(fm);
			this.datas = datas;
			this.context = context;
		}

		@Override
		public Fragment getItem(int position) {
			DishesViewPagerFragment f = new DishesViewPagerFragment();
			return f;
		}

		@Override
		public int getCount() {
			return datas.size();
		}
		
		@Override
		public Object instantiateItem(ViewGroup container, int position) {
			DishesViewPagerFragment f = (DishesViewPagerFragment) super.instantiateItem(container, position);
			Dish dish = datas.get(position);
			f.instance(f, dish, context);
			return f;
		}
		
		@Override
		public int getItemPosition(Object object) {
			return PagerAdapter.POSITION_NONE;
		}
	}
	
    /*
     * 菜肴的fragment
     * */
	public static class DishesViewPagerFragment extends Fragment{
		private Dish dish;
		private int num;
		private MenuCartDao fragment_dish_dao;
		private DishUtil fragment_dish_util;
		private String TABLE_NAME = "menu_cart";
		private Context context;
		private MenuDishDao dish_dao;
		private TextView dishsetContentTv;
		
		
//		public DishesViewPagerFragment(Context context){
//			this.context = context;
//		}
		
		public DishesViewPagerFragment(){
			
		}
			public  void instance(DishesViewPagerFragment vp,Dish dish,Context context){
				vp.setDish(dish);
				vp.context = context;
			}
			
			@Override
			public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			dish = getDish();
			fragment_dish_dao = MenuCartDao.getInstance(getActivity());
			fragment_dish_util = DishUtil.getInstance(getActivity());
			dish_dao = MenuDishDao.getInstance(getActivity());
			}
			
			@Override
			public View onCreateView(LayoutInflater inflater,
					ViewGroup container, Bundle savedInstanceState) {
			        View view = inflater.inflate(R.layout.fragment_dishessetshow, null);
			        final LinearLayout show_pageLy = (LinearLayout)view.findViewById(R.id.show_pageLy);
			        /*
			         * 处理图片
			         * */
			        final ViewPager dishesset_show_viewpager = (ViewPager)view.findViewById(R.id.dishesset_show_viewpager);
			        if(dish.getPicUrls()!=null && dish.getPicUrls().size()>0&& !dish.getPicUrls().contains(null)){
			        	PicAdapter picAdapter = new PicAdapter(getChildFragmentManager(), dish.getPicUrls(),context);
						dishesset_show_viewpager.setAdapter(picAdapter);
						dishesset_show_viewpager.setPageTransformer(true, new ZoomOutPageTransformer());
						
						//处理多张图片上的指示点
						List<String> picUrls = dish.getPicUrls();
						final int pageNum = picUrls.size();
						final ImageView[] pages = new ImageView[pageNum];
						if(pageNum>1){
						for(int i = 0;i<pageNum;i++){
							ImageView page = new ImageView(context);
							if(i==0){
								page.setImageResource(R.drawable.page_now);
							}else{
							page.setImageResource(R.drawable.page);
							}
							pages[i] = page;
							show_pageLy.addView(page);
						}
						}
						dishesset_show_viewpager.setOnPageChangeListener(new OnPageChangeListener() {
							
							@Override
							public void onPageSelected(int position) {
								if(pageNum>1){
									show_pageLy.removeAllViews();
									for(int i = 0;i<pages.length;i++){
										if(i==position){
											pages[i].setImageResource(R.drawable.page_now);
										}else{
											pages[i].setImageResource(R.drawable.page);
										}
										show_pageLy.addView(pages[i]);
									}
								}
							}
							
							@Override
							public void onPageScrolled(int arg0, float arg1, int arg2) {
								
							}
							
							@Override
							public void onPageScrollStateChanged(int arg0) {
								
							}
						});
						
			        }else{
			        	List<String> picUrls = new ArrayList<String>();
			        	picUrls.add("");
			          	PicAdapter picAdapter = new PicAdapter(getChildFragmentManager(), picUrls,context);
						dishesset_show_viewpager.setAdapter(picAdapter);
						dishesset_show_viewpager.setPageTransformer(true, new ZoomOutPageTransformer());
			        } 
			        
			        /*
			         * 处理名字以及加减菜肴
			         * */
			        final TextView show_ds_name = (TextView)view.findViewById(R.id.show_ds_name);
			        show_ds_name.setText(dish.getDishesName());
			        
			        num = fragment_dish_dao.getNum(dish.getDishesId());
			        
			        /*
			         * 这里面的控件当是套餐的时候是不显示的
			         * */
			        TextView dishNotesTv = (TextView)view.findViewById(R.id.show_dishnotesTv);
			        
			        /*
			         * 处理套餐以及可替换菜肴
			         * */
			        
			           final Button  dishConfirm =(Button) view.findViewById(R.id.show_confirm);
				        dishsetContentTv = (TextView)view.findViewById(R.id.show_dishsetContentTv);
				       Button dishsetChooseBtn = (Button)view.findViewById(R.id.show_dishsetChooseBtn);
				       if(dish.getIsSet().equals("true")&&dish.getDsDishes()!=null&&dish.getDsDishes().size()>0){
				    	   dishsetContentTv.setVisibility(View.VISIBLE);
				    	   dishsetChooseBtn.setVisibility(View.VISIBLE);
				    	   
					       StringBuilder sb = new StringBuilder("");
					       sb.append(dish.getDishesName()).append("(");
					        List<DishesSetDishes> dsDishes = dish.getDsDishes();
					       for(DishesSetDishes dsDishe:dsDishes){
					    	   sb.append(dsDishe.getDishesName());
					    	List<DishesSetDishesReplace>  replaceDishes =  dsDishe.getDishesSetDishesReplaces();
					    	for(DishesSetDishesReplace replaceDishe:replaceDishes){
					    		sb.append("/").append(replaceDishe.getDishesName());
					    	}
					    	if(!dsDishe.getDishesId().equals(dsDishes.get(dsDishes.size()-1).getDishesId())){
					    		sb.append(",").append("   ");
					    	}
					    	
					       }
					       sb.append(")");
					       dishsetContentTv.setText(sb.toString());
				       }else{
				    	   dishsetContentTv.setVisibility(View.GONE);
				    	   dishsetChooseBtn.setVisibility(View.GONE);
				       }
				       
				       dishsetChooseBtn.setOnClickListener(new OnClickListener() {
						
						@Override
						public void onClick(View v) {
							Intent intent = new Intent(context,CartEditActivity.class);
							intent.putExtra("type", "dish");
							intent.putExtra("dish", dish);
							intent.putExtra("page", "show");
							startActivityForResult(intent, 1);
						}
					});
			        /*
			         * 处理特价和原价的价格显示
			         * */
			        TextView dishsPriceTv = (TextView)view.findViewById(R.id.fragment_dish_sprice);
			        TextView dishPriceTv = (TextView)view.findViewById(R.id.fragment_dish_price);
					
			        if(dish.getIsRulingPrice()!=null && dish.getIsRulingPrice().equals("1")){
			        	dishsPriceTv.setVisibility(View.GONE);
			        	dishPriceTv.setText("￥"+dish.getRulingPrice()+"/"+dish.getUnitName());
			        }else{
			        if(dish.getSpecialPrice()!=null){
			        	dishsPriceTv.setText(Html.fromHtml("<font color='red' type='bold'>"+"￥"+dish.getSpecialPrice()+"/份"+"</font>"));
			        	dishPriceTv.setText("￥"+dish.getPrice());
			        	dishPriceTv.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
			        }else{
			        	dishsPriceTv.setVisibility(View.GONE);
			        	dishPriceTv.setText("￥"+dish.getPrice()+"/"+dish.getUnitName());
			        }
			        }
			        /*
			         * 处理是否显示时价字样
			         * */
			        if(dish.getIsRulingPrice()!=null && dish.getIsRulingPrice().equals("1")){
			        	view.findViewById(R.id.fragment_dish_isrunlingprice).setVisibility(View.VISIBLE);
			        }
			        /*
			         * 处理特价字段的显示
			         * */
			        LinearLayout spInterLy = (LinearLayout)view.findViewById(R.id.show_spi_ly);
			        if(dish.getSpecialDishes()!=null && dish.getSpecialDishes().size()>0){
			        	spInterLy.setVisibility(View.VISIBLE);
			        	List<SpecialDishe> spDishes = dish.getSpecialDishes();
			        	for(SpecialDishe spDishe:spDishes){
			        		FlowLinearLayout flowLy = new FlowLinearLayout(context);
			        		if(spDishe.getSpDateStr()!=null && !spDishe.getSpDateStr().equals("")){
			        			TextView spDateTv = new TextView(context);
				        		spDateTv.setText(spDishe.getSpDateStr());
				        		spDateTv.setTextColor(getResources().getColor(R.color.dark_brown));
				        		flowLy.addView(spDateTv);
			        		}
			        		if(spDishe.getSpTime()!=null && !spDishe.getSpTime().equals("")){
				        		TextView spTimeTv = new TextView(context);
				        		spTimeTv.setText(spDishe.getSpTime());
				        		spTimeTv.setTextColor(getResources().getColor(R.color.dark_brown));
				        		flowLy.addView(spTimeTv);
			        		}
			        		if(spDishe.getSpecialPrice()!=null){
				        		TextView spPriceTv = new TextView(context);
				        		spPriceTv.setText(spDishe.getSpecialPrice()+"元");
				        		spPriceTv.setTextColor(Color.RED);
				        		flowLy.addView(spPriceTv);
			        		}
			        		spInterLy.addView(flowLy);
			        	}
			        }else{
			        	spInterLy.setVisibility(View.GONE);
			        }
			        
			        /*
			         * 处理菜肴的菜系
			         * */
			      TextView dishStyleTv = (TextView) view.findViewById(R.id.show_dishStyleTv);
			      if(dish.getDishesStyleStr()==null ||  dish.getDishesStyleStr().equals("null")){
			       dishStyleTv.setVisibility(View.GONE);
			      }else{
			    	  if(dish.getDishesStyleStr().equals("")){
			    		  dishStyleTv.setText("菜系：暂无菜系介绍");
			    	  }else{
			    		  dishStyleTv.setText("菜系："+dish.getDishesStyleStr());
			    	  }
			    	  dishStyleTv.setVisibility(View.VISIBLE);
			      }
			        /*
			         * 处理菜肴的食材
			         * */
			      TextView dishMaterialTv = (TextView)view.findViewById(R.id.show_dishMaterialTv);
			      if(dish.getDishesMaterialStr()==null ||dish.getDishesMaterialStr().equals("null")){
			    	  dishMaterialTv.setVisibility(View.GONE);
				      }else{
				    	  if(dish.getDishesMaterialStr().equals("")){
				    		  dishMaterialTv.setText("食材：暂无食材介绍");
				    	  }else{
				    		  dishMaterialTv.setText("食材："+dish.getDishesMaterialStr());
				    	  }
				    	  dishMaterialTv.setVisibility(View.VISIBLE);
				      }
			        /*
			         * 处理菜肴的口味
			         * */
			     TextView dishTasteTv = (TextView) view.findViewById(R.id.show_dishTasteTv);
			      if(dish.getDishesTasteStr()==null ||dish.getDishesTasteStr().equals("null")){
			    	  dishTasteTv.setVisibility(View.GONE);
				      }else{
				    	  if(dish.getDishesTasteStr().equals("")){
				    		  dishTasteTv.setText("口味：暂无口味介绍");
				    	  }else{
				    		  dishTasteTv.setText("口味："+dish.getDishesTasteStr());
				    	  }
				    	 dishTasteTv.setVisibility(View.VISIBLE);
				      }
			        /*
			         * 处理菜肴的辣度
			         * */
			    LinearLayout  pungelLy = (LinearLayout)view.findViewById(R.id.show_dishpungelLy);
			    TextView dishpungelTv = (TextView)view.findViewById(R.id.show_dishpungel);
			    ImageView show_p1 = (ImageView)view.findViewById(R.id.show_p1);
			    ImageView show_p2 = (ImageView)view.findViewById(R.id.show_p2);
			    ImageView show_p3 = (ImageView)view.findViewById(R.id.show_p3);
			    ImageView show_p4 = (ImageView)view.findViewById(R.id.show_p4);
			    ImageView show_p5 = (ImageView)view.findViewById(R.id.show_p5);
			    String punLevel = dish.getPungentLevel();
			    dishpungelTv.setText(punLevel);
			    if(punLevel!=null && !punLevel.equals("")){
			    	pungelLy.setVisibility(View.VISIBLE);
				     if(punLevel.equals("不辣")){
				    	 show_p1.setBackgroundResource(drawable.pungel_yes);
				     }else if(punLevel.equals("微辣")){
				    	 show_p1.setBackgroundResource(drawable.pungel_yes);
				    	 show_p2.setBackgroundResource(drawable.pungel_yes);
				     }else if(punLevel.equals("中辣")){
				    	 show_p1.setBackgroundResource(drawable.pungel_yes);
				    	 show_p2.setBackgroundResource(drawable.pungel_yes);
				    	 show_p3.setBackgroundResource(drawable.pungel_yes);
				     }else if(punLevel.equals("辣")){
				    	 show_p1.setBackgroundResource(drawable.pungel_yes);
				    	 show_p2.setBackgroundResource(drawable.pungel_yes);
				    	 show_p3.setBackgroundResource(drawable.pungel_yes);
				    	 show_p4.setBackgroundResource(drawable.pungel_yes);
				     }else if(punLevel.equals("特辣")){
				    	 show_p1.setBackgroundResource(drawable.pungel_yes);
				    	 show_p2.setBackgroundResource(drawable.pungel_yes);
				    	 show_p3.setBackgroundResource(drawable.pungel_yes);
				    	 show_p4.setBackgroundResource(drawable.pungel_yes);
				    	 show_p5.setBackgroundResource(drawable.pungel_yes);
				     }
			    }else if(punLevel==null || punLevel.equals("")){
			    	pungelLy.setVisibility(View.INVISIBLE);
			    }

		        /*
		         * 处理菜肴的备注
		         * */
			   String notes =  dish.getNotes();
			    if(notes!=null && !notes.equals("")){
			    	dishNotesTv.setVisibility(View.VISIBLE);
			    	dishNotesTv.setText("美食故事："+notes);
			    }else if(notes!=null && notes.equals("")){
			    	dishNotesTv.setVisibility(View.VISIBLE);
			    	dishNotesTv.setText("暂无美食故事");
			    	dishNotesTv.setTextSize(ActivityUtil.dip2px(context, 24));
			    	dishNotesTv.setTextColor(getResources().getColor(R.color.gray));
			    	dishNotesTv.setGravity(Gravity.CENTER);
			    }
			        /*
			         * 处理估清菜肴,来一份按钮
			         * */
			        if(dish.getEstimate()!=null &&dish.getEstimate()<=0f){
			        	dishConfirm.setEnabled(false);
			        }else{
			        	dishConfirm.setEnabled(true);
				        dishConfirm.setOnClickListener(new OnClickListener() {
							
							@Override
							public void onClick(View v) {
									//保存到已点菜肴的表中
								final Handler handler = new Handler(){
									@Override
									public void handleMessage(Message msg) {
										super.handleMessage(msg);
										//如果不在特价时段内，重新定义特价就是原价，插入购物车列表
										if(msg.getData().getString("priceStr").equals("null")){
											dish.setSpecialPrice(dish.getPrice());
										}
										//套餐的情况
										 if(dish.getIsSet().equals("true")&&dish.getDsDishes()!=null&&dish.getDsDishes().size()>0){
											fragment_dish_dao.insert(dish, fragment_dish_util, TABLE_NAME,context);
											dish_dao.updateAddNum(dish.getDishesId(), 1);
											//非套餐的情况
										 }else{
												int orderNum = fragment_dish_dao.getNum(dish.getDishesId());
												if(orderNum==0){
													fragment_dish_dao.insert(dish, fragment_dish_util, TABLE_NAME, context);
												}else{
													fragment_dish_dao.jiaorerdishesNum(dish.getDishesId());
												}
												dish_dao.addNum(dish.getDishesId());
												
										 }
											
											int[] startLocation = new int[2];
											dishConfirm.getLocationOnScreen(startLocation);
											
											CircleImageView circleImv = new CircleImageView(context);
											circleImv.setBackgroundResource(R.drawable.scroll);
											setAnim(circleImv,startLocation);
									}
								};
									
									//判断该菜肴是否在特价时段内并根据结果处理菜肴的价格显示。
									Thread judgePriceThread = new Thread(new Runnable() {
										private String priceStr = "";
										@Override
										public void run() {
											Message msg = handler.obtainMessage();
											if(dish.getSpecialPrice()!=null){
												SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");
												String creatTimeStr = format.format(new Date());
												BigDecimal price = DishService.judgePrice(dish.getDishesId(),dish.getIsSet(),creatTimeStr);
												priceStr  = price+"";
											}
												Bundle bundle = new Bundle();
												bundle.putString("priceStr", priceStr);
												msg.setData(bundle );
												handler.sendMessage(msg);
										}
									});
									judgePriceThread.start();
										
							}
						});
			        }

				return view;
			}
			
			public void setAnim(final View v, int[] start_location) {
				ViewGroup anim_mask_layout = null;//动画层
				anim_mask_layout = ActivityMenuUtil.createAnimLayout((ShowActivity)context);
				anim_mask_layout.addView(v);//把动画图片添加到动画层
				final View view = ActivityMenuUtil.addViewToAnimLayout(anim_mask_layout, v,
						start_location);//定义动画的开始位置
				int[] end_location = new int[2];// 这是用来存储动画结束位置的X、Y坐标
				orderNumTv.getLocationInWindow(end_location);// cartImv是那个购物车

				// 计算位移
				int endX = end_location[0] - start_location[0];// 动画位移的X坐标
				int endY = end_location[1] - start_location[1];// 动画位移的y坐标
				
				TranslateAnimation translateAnimationX = new TranslateAnimation(0,
						endX, 0, 0);
				
				TranslateAnimation translateAnimationY = new TranslateAnimation(0, 0,
						0, endY); 
//				AnticipateOvershootInterpolator AnticipateInterpolator  OvershootInterpolator    
//				translateAnimationY.setInterpolator(bdInterpolator);
				
				ScaleAnimation scaleAnimation = new ScaleAnimation(v.getScaleX(), 0.2f, v.getScaleY(), 0.2f);
				
				RotateAnimation rotateAnimation = new RotateAnimation(0, 360);
				
				AnimationSet set = new AnimationSet(false);
				set.setFillAfter(false);
				set.addAnimation(scaleAnimation);
				set.addAnimation(rotateAnimation);
				set.addAnimation(translateAnimationY);
				set.addAnimation(translateAnimationX);
				set.setDuration(1000);
				
			view.startAnimation(set);
				// 动画监听事件
				set.setAnimationListener(new AnimationListener() {
					// 动画的开始
					@Override
					public void onAnimationStart(Animation animation) {
						v.setVisibility(View.VISIBLE);
					}

					@Override
					public void onAnimationRepeat(Animation animation) {
					}

					// 动画的结束
					@Override
					public void onAnimationEnd(Animation animation) {
						v.setVisibility(View.GONE);
						cartOrderNum++;
						orderNumTv.setText(cartOrderNum+"");
					}
				});
			}
			
			class PicAdapter extends FragmentStatePagerAdapter{
				
				List<String> picUrls;
				Context context;
				public PicAdapter(FragmentManager fm, List<String> picUrls,Context context) {
					super(fm);
					this.picUrls = picUrls;
					this.context = context;
				}
				@Override
				public Fragment getItem(int position) {
					PicFragment sf = new PicFragment(context);
					Bundle subargs = new Bundle();
					subargs.putString("picUrl", picUrls.get(position));
					sf.setArguments(subargs);
					return sf;
					//return PicFragment.instance(picUrls.get(position),context);
				}
				@Override
				public int getCount() {
					return picUrls.size();
				}
				
			}
			
			static class PicFragment extends Fragment{
				String picUrl;
				Context context;
				
//				public PicFragment instance(String picUrl,Context context){
//					PicFragment sf = new PicFragment(context);
//					Bundle subargs = new Bundle();
//					subargs.putString("picUrl", picUrl);
//					sf.setArguments(subargs);
//					return sf;
//				}
				
				public PicFragment(Context context){
					this.context = context;
				}
				
				
				@Override
				public void onCreate(Bundle savedInstanceState) {
					super.onCreate(savedInstanceState);
					Bundle subargs = getArguments();
					if(subargs!=null){
						picUrl = subargs.getString("picUrl");
					}
				}
				
				@Override
				public View onCreateView(LayoutInflater inflater,
						ViewGroup container, Bundle savedInstanceState) {
					View view = inflater.inflate(R.layout.fragment_pic_show, null);
					ImageView dishesset_test = (ImageView)view.findViewById(R.id.pic_show_img);
//					if(picUrl!=null&& !picUrl.equals("")) {
						ActivityMenuUtil.loadImage(imageLoader, Constants.BASE_SERVIER_URLS+picUrl, dishesset_test,options, getActivity());
//					}
					return view;
				}
			}

			public Dish getDish() {
				return dish;
			}

			public void setDish(Dish dish) {
				this.dish = dish;
			}
			
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if(!isBlockScreen()){
		if(keyCode==KeyEvent.KEYCODE_BACK){
			application.setMenuMainIsRefresh(true);  
			ShowActivity.this.finish();
			this.overridePendingTransition(R.anim.in_from_top, R.anim.out_to_bottom);
		}
		return super.onKeyDown(keyCode, event);
		}else{
			return true;
		}
	}
	
	public  void Toast(String taostStr){
		LayoutInflater inflater = getLayoutInflater();
		View layout = inflater.inflate(R.layout.toast_layout,
		(ViewGroup) findViewById(R.id.toast_layout_root));

		ImageView image = (ImageView) layout.findViewById(R.id.image);
		image.setImageResource(R.drawable.toastimv);  
		TextView text = (TextView) layout.findViewById(R.id.text);
		text.setGravity(Gravity.CENTER_VERTICAL);
		text.setText(taostStr);

		Toast toast = new Toast(getApplicationContext());
		toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
		toast.setDuration(Toast.LENGTH_SHORT);
		toast.setView(layout);
		toast.show();
	}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
	super.onActivityResult(requestCode, resultCode, data);
	switch(resultCode){
	case RESULT_OK:
		String result = data.getStringExtra("result");
		if(result!=null && result.equals("edit")){
			Dish resultDish = (Dish)data.getSerializableExtra("resultDish");
		if(resultDish!=null){
			ActivityUtil.Toast(ShowActivity.this, resultDish.getDishesName(), false, false);
			for(int i=0;i<datas.size();i++){
				if(resultDish.getDishesName().equals(datas.get(i).getDishesName())){
					datas.set(i, resultDish);
					mMenuAdapter.notifyDataSetChanged();
				}
			}
		}
		}
		break;
		
	}
}

public boolean isBlockScreen() {
	return isBlockScreen;
}

public void setBlockScreen(boolean isBlockScreen) {
	this.isBlockScreen = isBlockScreen;
}
	
	
}
